London 9 - Lovelace - Oleksii Chepurnyi - JavaScript-Core1-Coursework-Week1 - #435
London 9 - Lovelace - Oleksii Chepurnyi - JavaScript-Core1-Coursework-Week1#435OleksChep wants to merge 23 commits into
Conversation
| var introduce2 = "characters long."; | ||
| var message = | ||
| introduce1 + name1 + " " + introduce3 + nameLength + " " + introduce2; | ||
| console.log(message.trim()); No newline at end of file |
| var ment = "Number of mentors: "; | ||
| console.log(ment + numberOfMentors); | ||
| var total = "Total number of students and mentors: "; | ||
| var sum = numberOfMentors + numberOfStudents; |
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| // Calculate the result of the function and return it | ||
| function multiply(a, b) { |
| function convertToUSD() {} | ||
| function convertToUSD(price) { | ||
| let priceDolar = pricePound*1.4; | ||
| return "$" + priceDolar.toFixed(2); |
There was a problem hiding this comment.
Excellent - toFixed is the right thing to use here
| return a + b + c; | ||
| } | ||
| function introduceMe(name, age) { | ||
| return "Hello, my name is " + '${name}' + "and I am " + '${age}' + " years old"; |
There was a problem hiding this comment.
Will '${name}' just print out the name?
|
|
||
| return "The total is total"; | ||
| total = a + b; | ||
| return "The total is ${total}"; |
There was a problem hiding this comment.
Close - you're using template string syntax here, but to make it work you need to use backticks ` instead of " to surround the string.
There was a problem hiding this comment.
If you don't use backticks then ${total} won't be replaced by the value of total. For instance:
let a = 34;
console.log("a is ${a}"); // will print: a is ${a}
console.log(`a is ${a}`); // will print: a is 34
| //The implementation selects the initial seed to the random number generation | ||
| //algorithm; it cannot be chosen or reset by the user. | ||
| //Return value A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). | ||
| // 0 < Number < 10 ; |
There was a problem hiding this comment.
The generated number will be between 0 and 1
so, 0 < Number < 1
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(price) { | ||
| let newPrice = calculateSalesTax(price); | ||
| return "£" + newPrice.toFixed(2); |
There was a problem hiding this comment.
Excellent. Maybe one small improvement? Every time you use the calculateSalesTax function, you'll have to call toFixed on the result. How can you save from having to do that each time you call it?
There was a problem hiding this comment.
do not understand question , sorry
There was a problem hiding this comment.
Well done, you've got it mostly right.
Did you run the tests, as explained in the README file?
Not all of them pass, so I just want to check if you managed to run them yourself?
Also, when you answer the questions (what did you find easy, etc), you're allowed to use more than one word!
And thanks a lot @jonnywyatt for your review :)
| @@ -1,3 +1,7 @@ | |||
| // Start by creating a variable `greeting` | |||
|
|
|||
| var greeting = "Hello world"; | |||
There was a problem hiding this comment.
You should avoid var. As mentioned last week, prefer using let or const. var is old, has tricky semantics, and is no longer needed.
|
|
||
| var name1 = "Oleks"; | ||
| var nameLength = name1.length; | ||
| var introduce1 = " My name is "; |
| var total = "Total number of students and mentors: "; | ||
| var sum = numberOfMentors + numberOfStudents; | ||
| console.log(total + sum); | ||
| var percentageStudents = 100*numberOfStudents/sum |
There was a problem hiding this comment.
Don' forget the ; at the end of the line. Even if it won't change the behaviour of your code, it's better to stay consistent.
| // Declare your function first | ||
|
|
||
| function divide ( a, b) { | ||
| return a / b; |
There was a problem hiding this comment.
The indentation of this line is 4 characters, while you use 1 above in your code. Again, for the sake of consistency and readability, always use the same amount.
| */ | ||
|
|
||
| function convertToUSD() {} | ||
| function convertToUSD(price) { |
There was a problem hiding this comment.
I think you meant pricePound here.
Otherwise it's good idea to use the currency in the name of the variable or parameter. Same with units: distanceInMeters, waveLengthCm, etc. It can be useful to avoid any confusion when sharing your code.
|
|
||
| function getStringLength(word) { | ||
| return "word".length(); | ||
| return word.length(); |
There was a problem hiding this comment.
It's word.length. It's unclear why JavaScript does it this way, so we just accept it :)
|
Thanks for the review |
|
|
How |
|
To run the tests, see the instructions: |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
Operators
Functions / TESTS !
Tests / How it works ?
How works Tests ?
View rendered exercises/K-functions-parameters/README.md